package com.after.saas.file.handler;

import com.after.saas.file.constants.MedalTitleEnum;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @Description
 * @Classname MedalContext
 * @Author hjchen
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2023/4/7 15:31
 */

@Component
public class MedalContext {

    private final MedalLevelFactory medalLevelFactory;

    public MedalContext(MedalLevelFactory medalLevelFactory) {
        this.medalLevelFactory = medalLevelFactory;
    }

    public MedalRecord saveMedalRecord(BigDecimal sumPoints) {
        MedalLevel qt = medalLevelFactory.generateLevel(MedalTitleEnum.BRONZE.name());
        MedalLevel by = medalLevelFactory.generateLevel(MedalTitleEnum.SILVER.name());
        MedalLevel hj = medalLevelFactory.generateLevel(MedalTitleEnum.GOLD.name());
        MedalLevel bj = medalLevelFactory.generateLevel(MedalTitleEnum.PLATINUM.name());
        MedalLevel zs = medalLevelFactory.generateLevel(MedalTitleEnum.MASONRY.name());
        qt.setNext(by);
        by.setNext(hj);
        hj.setNext(bj);
        bj.setNext(zs);
        return qt.handleRequest(sumPoints);
    }

}
